package apps.softtech.fastmarket.adapter;

import java.util.ArrayList;

import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import apps.softtech.Utility.ApplicationConstants;
import apps.softtech.fastmarket.R;
import apps.softtech.fastmarket.model.UserInfo;

public class AdapterMyProfileFollowing extends BaseAdapter{

	ArrayList<UserInfo> mFollowUsersList = new ArrayList<UserInfo>();
	LayoutInflater inf;
	Context mContext;
	DisplayImageOptions options;
	public AdapterMyProfileFollowing(Context mContext,ArrayList<UserInfo> mFollowUsersList,DisplayImageOptions options ){
		this.mContext = mContext;
		this.mFollowUsersList = mFollowUsersList;
		inf = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		this.options=options;
	}
	@Override
	public int getCount() {
		if(mFollowUsersList.size()==0){
			return 1;
		}
		return mFollowUsersList.size();
	}

	@Override
	public Object getItem(int arg0) {
		return null;
	}

	@Override
	public long getItemId(int arg0) {
		return 0;
	}

	@Override
	public View getView(int position, View vi, ViewGroup arg2) {
		if(mFollowUsersList.size()==0||mFollowUsersList==null){
			vi = inf.inflate(R.layout.search_no_result, null);
			TextView tvNoResult = (TextView)vi.findViewById(R.id.tvNoResult);
			tvNoResult.setText("No following");
			return vi;
		}
		ViewHolder vh = null;
		if(vi==null){
			vi=inf.inflate(R.layout.item_my_profile_following, null);
			vh = new ViewHolder();
			vh.ivFollowing = (ImageView)vi.findViewById(R.id.ivMyProfileFollowing);
			vh.tvFollowing = (TextView)vi.findViewById(R.id.tvMyProfileFollowingInfo);
			vi.setTag(vh);
		}else{
			vh = (ViewHolder) vi.getTag();
		}
		vh.tvFollowing.setText(""+mFollowUsersList.get(position).getUserName());
		String url = ApplicationConstants.BASE_URL_IMAGE + mFollowUsersList.get(position).getAvatarPath();
		ImageLoader.getInstance().displayImage(url, vh.ivFollowing, options);
		return vi;
	}
	class ViewHolder{
		ImageView ivFollowing;
		TextView tvFollowing;
	}

}
